home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993 October: Windmill on DISC / ADC Developer CD (1993-10) (''Windmill On DISC'')_iso / Dev.CD Oct 93.iso / Utilities / Installer v3.4.3 / Examples - Installer 3.4 / Action Atom Samples / CustomFolderIconAA / SetFolderIcon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  3.7 KB  |  122 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2.  *
  3.  *    Apple Macintosh Developer Technical Support
  4.  *
  5.  *  Installer 3.2 sample: Action Atoms
  6.  *
  7.  *    File:        SetFolderIcon.c -    c Source
  8.  *
  9.  *    by:            Rich Kubota
  10.  *
  11.  *    Copyright © 1990-1992 Apple Computer, Inc.
  12.  *    All rights reserved.
  13.  *
  14.  *    Purpose: Sample to demonstrate setting a custom folder icon.  The script
  15.  *        needs to copy the folder icon file as demonstrated in the 
  16.  *        CustomFoldIconInstall.r script.  This code resource must then be called
  17.  *        to clear the folder's init'd bit and to set the folders "Use Custom Icon" bit.
  18.  *        In the selector field of the 'inaa' resource, pass in the id of the target 
  19.  *        'infs' resource id for the icon.  The code resource gets the resource, converts the 
  20.  *        partial path name field to a pascal string for the enclosing folder.  The
  21.  *        code resource calls PHGetCatInfo to get the directory info.  The necessary 
  22.  *        bits are set/cleared, and PBSetCatInfo is called.  The return value of
  23.  *        noErr is always returned so as not to abort the installation.
  24.  *----------------------------------------------------------------------------*/
  25.  
  26. #if 0
  27.  
  28. C -r -b  SetFolderIcon.c    
  29. Link -ra =resPurgeable -t rsrc -c RSED -rt infn=10000 ∂
  30.     -m SETFOLDERICON -sg SetFolderIcon ∂
  31.     SetFolderIcon.c.o ∂
  32.     "{Libraries}"Interface.o ∂
  33.     -o SetFolderIcon.rsrc
  34.  
  35. #endif
  36.  
  37. #include <Types.h>
  38. #include <Resources.h>
  39. #include <Files.h>
  40. #include "ActionAtomIntf.h"
  41.  
  42. /* define record structure of 'infs' resource so that we can access the target file path */
  43.  
  44. struct infsRec {
  45.     long    fileType;
  46.     long    creator;
  47.     long    creationDate;
  48.     short    fileSpecFlags;
  49.     Str255    pathName;
  50.     
  51. };
  52.  
  53. typedef struct infsRec infsRec;
  54. typedef infsRec **infsHdl;
  55.  
  56. /* protoypes */
  57. OSErr    StripFileName(char *str);
  58.  
  59. pascal long    SETFOLDERICON(AAPBRecPtr myAAPBPtr)
  60. {
  61.     OSErr        err;
  62.     infsHdl        resH;
  63.     CInfoPBRec    info;
  64.     DInfo        *myDirInfo;
  65.     
  66.     if (myAAPBPtr->whichStage == after) /* only run if doing post-installation */
  67.                             /* Note 1. action atoms marked as actAfter will also
  68.                              *          *receive a cleanUpCancel message if the
  69.                              *           installation is cancelled so we need to test
  70.                              *           the stage here, else we could get called 
  71.                              *           twice.
  72.                              * Note 2. to be more robust, we might also include 
  73.                              *         the option to respond to a cleanUpCancel message to
  74.                              *         remove the icon and folder
  75.                              */
  76.     {
  77.         resH = (infsHdl)GetResource('infs', myAAPBPtr->aaRefCon);
  78.         if (resH) {
  79.             if (StripFileName((*resH)->pathName) == noErr) {
  80.                 info.dirInfo.ioCompletion = nil;
  81.                 info.dirInfo.ioVRefNum = myAAPBPtr->targetVRefNum;
  82.                 info.dirInfo.ioNamePtr = (*resH)->pathName;
  83.                 info.dirInfo.ioFDirIndex = 0;
  84.                 info.dirInfo.ioDrDirID = 0;
  85.                 
  86.                 if (PBGetCatInfo(&info, false) == noErr) {
  87.                     myDirInfo = &info.dirInfo.ioDrUsrWds;
  88.                     myDirInfo->frFlags &= 0xFEFF;    
  89.                                 // clear the init'd bit
  90.                     myDirInfo->frFlags |= 0x0400;    
  91.                                 // set the "Use Custom Folder Icon" bit
  92.                                 
  93.                                 // now that the ioDrDirID field is filled in corectly
  94.                                 // let's use it to identify the directory instead of the name ptr.
  95.                     info.dirInfo.ioNamePtr = nil;
  96.                     info.dirInfo.ioFDirIndex = -1;
  97.                     err = PBSetCatInfo(&info,false);
  98.                 }
  99.             }
  100.             ReleaseResource((Handle)resH);
  101.         }
  102.     }        
  103.     return noErr; // Since the installation reached this point, dont abort 
  104. }
  105.  
  106. //    This routine strips the filename and the preceding ':' character from the
  107. //     pathname.
  108. //    Input - pointer to file pathname
  109. //    Output - modifies pointer
  110. OSErr    StripFileName(char *str)
  111. {
  112.     unsigned char len = str[0];
  113.     
  114.     while ((str[len] != ':') && (len > 0)) 
  115.         len--;
  116.     
  117.     if (len > 0) {
  118.         str[0] = len - 1;    // parse the ":" from the end of the pathname
  119.         return noErr;
  120.     }
  121.     return -1;
  122. }